
# include "dfxGraphicsPlugin.h"

namespace DFX
{
    GraphicsPlugin::GraphicsPlugin(const String &dllFile)
        : Plugin("Graphics"), mDllFile(dllFile),
        mCreateGraphicsDevice(NULL)
    {
    }

    GraphicsPlugin::~GraphicsPlugin()
    {
        Unload();
    }

    DFXRESULT GraphicsPlugin::CreateGraphicsDevice(GraphicsDevice **gd)
    {
        if (mCreateGraphicsDevice)
            return mCreateGraphicsDevice(gd);

        return DFX_ERROR0;
    }

    DFXRESULT GraphicsPlugin::Load()
    {
        LoadDLL(mDllFile, (void*)&mHandle);

        if (mHandle)
        {
            mCreateGraphicsDevice = (CREATEGRAPHICSDEVICE)GetFunction("CreateGraphicsDevice", (void*)&mHandle);
            return DFX_SUCCESS;
        }

        return DFX_ERROR0;
    }

    DFXRESULT GraphicsPlugin::Unload()
    {
        if (mHandle)
            UnloadDLL((void*)&mHandle);

        return DFX_SUCCESS;
    }
}